Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

208
Vistas
Looking to remove any value after :->

I am looking to remove any value after ':->' in JavaScript For example if 'Packet:->3', I would like to store "Packet:->" in the variable so I can use it before the if statement seen below. Pretty much I am looking to remove any digits after '>'

I was trying the below, but did not have much luck.

NTEremoved = NTE.indexOf(':->');

What would be the best way of doing this?

if(NTE == 'Packet:->' || NTE == 'Serving:->' || NTE == 'Can/Carton/Bottle:->'){

} 
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

String split.

const testStr1 = "Packet:->3";
const testStr2 = "BlahBlahBlah278:->Hello hello this is cool";
const result1 = testStr1.split(":->")[0] + ":->"; // split "splits" the string into an array based on the delimiter ":->"; the second part would be 3
const result2 = testStr2.split(":->")[0] + ":->";
console.log(result1);
console.log(result2);

Docs.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I would do something like this, to take care also of edge cases (assuming you don't care about what is coming after the first :->:

let texts = ["Packet:->11", "Cat:->22", "Packet:->:->:->44"];

for (let text of texts) {
  console.log(text.replace(/(:->).*$/, "$1"))
}

about 4 years ago · Juan Pablo Isaza Denunciar

0

Since you have mentioned you have tries to use indexOf before but fail to do that, I will provide you a way using a combination of indexOf and String.slice

let string = "Serving:->3"
//Indexof return the first index of an element so you have to add 3 (the length of ":->"
let newstring = string.slice(0,string.indexOf(":->")+3)

console.log(newstring)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda